<?php
// this just ensures noone can run this script without going through the application
if( !defined('PIH' ) ) {
    header('HTTP/1.0 404 Not Found');
    exit();
}
?>
<div style="text-align: center;">
<h3>Image Hotlinking and Bandwidth Monitoring Options</h3>
<p>
These options let you determine whether thumbnails and full size images on your site can be hotlinked
(embedded in other web pages) and whether thumbnail and image views count towards your user's bandwidth
allowance.
</p>
<p>
It also allows you to setup .htaccess rules to disallow people to view directory listings on your server,
and to rewrite urls from older versions of php image host (pre-1.4) so that any links to your site remain.
</p>
<?php if( $updated ){ ?>
<div style="color: #000099; font-weight: bold; text-align: center;">
	<h2>Hotlinking and bandwidth monitoring settings updated</h2>
	<?php if( !$rewritten ){ ?>
	<h3 style="color: red;">IMPORTANT! You must manually edit the file:</h3>
		<p><i><?php echo APP_DIR.'/.htaccess'?></i></p>
		<p>and copy and paste the rewrite rules at the bottom of this page into it
		in order for these changes to take effect.</p>
		<p>Ensure that you replace anything in the file between:</p>
		<p><i>##begin phpimagehost rewrite rules##</i></p>
		<p>and</p>
		<p><i>##end phpimagehost rewrite rules##</i></p>
	<?php } ?>
</div>
<?php } ?>
<form id="sidebarform" action="<?php echo $this->url('hotlinkbandwidth')?>" method="post">
	<table class="formtable" cellspacing="1" border="0" cellpadding="0" align="center">
	<tr>
		<td class="formlabel">Allow hotlinking for:</td>
		<td class="formfield">
			<input type="checkbox" name="hotlink_thumbnails" value="1" <?php if( $this->app->config->hotlink_thumbnails) echo ' checked="checked" '?> />
			Thumbnails
		</td>
		<td class="formfield">
			<input type="checkbox" name="hotlink_images" value="1" <?php if( $this->app->config->hotlink_images) echo ' checked="checked" '?> />
			Full size images
		</td>
	</tr>

	<tr>
		<td class="formlabel">Bandwidth Monitoring</td>
		<td class="formfield">
			<b>Thumbnails</b><br />
			<select name="monitor_thumbnail_bandwidth">
				<option value="0">Do not monitor thumbnails</option>
				<option value="1"<?php if( $this->app->config->monitor_thumbnail_bandwidth == 1 ) echo ' selected="selected" '?>>For hotlinked thumbnails</option>
				<option value="2"<?php if( $this->app->config->monitor_thumbnail_bandwidth == 2 ) echo ' selected="selected" '?>>All excluding admin or owner</option>
				<option value="3"<?php if( $this->app->config->monitor_thumbnail_bandwidth == 3 ) echo ' selected="selected" '?>>All excluding admin</option>
				<option value="4"<?php if( $this->app->config->monitor_thumbnail_bandwidth == 4 ) echo ' selected="selected" '?>>For all thumbnail views</option>
			</select>
		</td>
		<td class="formfield">
			<b>Full Size Images</b><br />
			<select name="monitor_image_bandwidth">
				<option value="0">Do not monitor images</option>
				<option value="1"<?php if( $this->app->config->monitor_image_bandwidth == 1 ) echo ' selected="selected" '?>>For hotlinked images</option>
				<option value="2"<?php if( $this->app->config->monitor_image_bandwidth == 2 ) echo ' selected="selected" '?>>All excluding admin or owner</option>
				<option value="3"<?php if( $this->app->config->monitor_image_bandwidth == 3 ) echo ' selected="selected" '?>>All excluding admin</option>
				<option value="4"<?php if( $this->app->config->monitor_image_bandwidth == 4 ) echo ' selected="selected" '?>>All image views</option>
			</select>
		</td>
	</tr>

	<tr>
		<td class="formlabel">Link / Embedding Code</td>
		<td class="formfield">
			<b>Thumbnails</b><br />
			<input type="checkbox" name="browse_thumb_links" value="1" <?php if( $this->app->config->browse_thumb_links ) echo ' checked="checked" '?> />
			Link Codes
			<br />
			<input type="checkbox" name="browse_thumb_embed" value="1" <?php if( $this->app->config->browse_thumb_embed ) echo ' checked="checked" '?> />
			Embedding Codes
			<br />
			<input type="checkbox" name="browse_thumb_bbcode" value="1" <?php if( $this->app->config->browse_thumb_bbcode ) echo ' checked="checked" '?> />
			BBCodes for forums
		</td>
		<td class="formfield">
			<b>Full Size Images</b><br />
			<input type="checkbox" name="browse_image_links" value="1" <?php if( $this->app->config->browse_image_links ) echo ' checked="checked" '?> />
			Link Codes
			<br />
			<input type="checkbox" name="browse_image_embed" value="1" <?php if( $this->app->config->browse_image_embed ) echo ' checked="checked" '?> />
			Embedding Codes
			<br />
			<input type="checkbox" name="browse_image_bbcode" value="1" <?php if( $this->app->config->browse_image_bbcode ) echo ' checked="checked" '?> />
			BBCodes for forums
		</td>
	</tr>

    <tr>
		<td class="formlabel">Rewrite URLs?</td>
		<td class="formfield" colspan="2">
			<input type="checkbox" name="rewrite_urls" value="1" <?php if( $this->app->config->rewrite_urls) echo ' checked="checked" '?> />
			Check this box to use urls that look like: /browse/username/myname/image/1 instead
            of urls that look like: /?cmd=browse&username=myname&image=1
		</td>
	</tr>
<!--
    <tr>
		<td class="formlabel">Rewrite <b>Old</b> URLs?</td>
		<td class="formfield" colspan="2">
			<input type="checkbox" name="rewrite_old_urls" value="1" <?php if( $this->app->config->rewrite_old_urls) echo ' checked="checked" '?> />
            Check this box if you upgraded from an older (1.3.x or earlier) version of php image host and you want to redirect any requests
            for the old urls (from existing links etc) to the new ones. Hopefully preserves any benefit from existing links to your website.
		</td>
	</tr>
-->
    <tr>
		<td class="formlabel">No Directory Browsing</td>
		<td class="formfield" colspan="2">
			<input type="checkbox" name="htaccess_no_indexes" value="1" <?php if( $this->app->config->htaccess_no_indexes) echo ' checked="checked" '?> />
            Check this box to add a rule to your .htaccess file to prevent your server from listing the contents of directories if for example a
            user browses to www.yoursite.com/images/
            <br />(Note: Your web server may already be configured to do this)
		</td>
	</tr>

    <tr>
		<td class="formlabel">&nbsp;</td>
		<td class="formfield" colspan="2">
            <b>
            IMPORTANT! - If after modifying your settings you are no longer able to access your site (server error) then delete the .htaccess file and ask for help on the <a href="http://forum.phpace.com/">support forum</a>
            </b><br />
            <input type="submit" name="update" value="Save Changes" onclick="alert('IMPORTANT! - If after modifying your settings you are no longer able to access your site (server error) then delete the .htaccess file and ask for help on the support forum');" />
		</td>
	</tr>

	<tr>
		<td class="formlabel">.htaccess code</td>
		<td class="formfield" colspan="2">
			<textarea rows="8" onfocus="this.select();" cols="40"><?php echo htmlspecialchars($rewrite)?></textarea>
		</td>
	</tr>

	</table>
</form>
</div>
